package com.posjiajia.user.operator.controller;

import com.posjiajia.commom.utils.vo.result.BaseResult;
import com.posjiajia.commom.utils.vo.result.DataResult;
import com.posjiajia.user.core.bo.DeviceBo;
import com.posjiajia.user.core.params.DeviceQueryParam;
import com.posjiajia.user.core.vo.DeviceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhenhua.sun
 * @title com.posjiajia.user.operator.controller
 * @date 9/25/16
 */
@Controller
@RequestMapping("device")
public class DeviceController {

    @Autowired
    private DeviceBo deviceBo;

    @RequestMapping("post")
    @ResponseBody
    public BaseResult post(DeviceVo deviceVo){
        if (deviceVo.getDeviceId() != null){
            deviceBo.update(deviceVo);
        }else
            deviceBo.insert(deviceVo);
        return BaseResult.SUCCESS;
    }


    @RequestMapping("query")
    @ResponseBody
    public DataResult query(DeviceQueryParam deviceQueryParam){
        DataResult baseResult = new DataResult();
        List<DeviceVo> voList = deviceBo.query(deviceQueryParam);
        baseResult.setData(voList);
        return baseResult;
    }
}
